{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import threading\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "def job1():\n",
    "    global A,lock\n",
    "    lock.acquire()\n",
    "    for i in range(10):\n",
    "        A +=1\n",
    "        print('jon1 ',A)\n",
    "    lock.release()\n",
    "    \n",
    "    \n",
    "def job2():\n",
    "    global A,lock\n",
    "    lock.acquire()\n",
    "    for i in range(10):\n",
    "        A +=10\n",
    "        print('job2',A)\n",
    "    lock.release()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "jon1  1\n",
      "jon1  2\n",
      "jon1  3\n",
      "jon1  4\n",
      "jon1  5\n",
      "jon1  6\n",
      "jon1  7\n",
      "jon1  8\n",
      "jon1  9\n",
      "jon1  10\n",
      "job2 20\n",
      "job2 30\n",
      "job2 40\n",
      "job2 50\n",
      "job2 60\n",
      "job2 70\n",
      "job2 80\n",
      "job2 90\n",
      "job2 100\n",
      "job2 110\n"
     ]
    }
   ],
   "source": [
    "if __name__==\"__main__\":\n",
    "    lock = threading.Lock()\n",
    "    A = 0\n",
    "    t1 =threading.Thread(target=job1)\n",
    "    t2 =threading.Thread(target=job2)\n",
    "    t1.start()\n",
    "    t1.join()\n",
    "    t2.start()\n",
    "    t2.join()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
